home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Applications / NIH Image 1.55 / Source / Text.p < prev    next >
Encoding:
Text File  |  1994-03-21  |  17.0 KB  |  664 lines  |  [TEXT/PJMM]

  1.  MakeNewTextWindow (name: str255; width, height: integer): boolean;
  2.     function OpenTextFile (name: str255; RefNum: integer): boolean;
  3.     procedure DoKeyDownInText (ch: char);
  4.     procedure ChangeFontOrSize;
  5.     procedure DoTextCopy;
  6.     procedure DoTextPaste;
  7.     procedure DoTextClear;
  8.     procedure SaveText;
  9.     procedure SaveTextAs;
  10.     function SaveTextChanges: integer;
  11.     procedure InsertText (str: str255; EndOfLine: boolean);
  12.     procedure DoFind;
  13.     procedure DecrementTextWindowNums (num: integer);
  14.  
  15.  
  16. implementation
  17.  
  18.  
  19.     type
  20.         CharArrayType = packed array[0..32767] of char;
  21.         CharArrayPtr = ^CharArrayType;
  22.  
  23.  
  24.     procedure UpdateScrollBars;
  25.         var
  26.             vMax, vValue, hMax, hValue: integer;
  27.     begin
  28.         with TextInfo^ do begin
  29.                 hlock(handle(TextTE));
  30.                 with TextTE^^, TextTE^^.viewRect do begin
  31.                         vTextPageSize := (bottom - top) div LineHeight;
  32.                         hTextPageSize := right - left;
  33.                         vMax := nLines - vTextPageSize;
  34.                         hMax := 0;
  35.                         vValue := (top - destRect.top) div LineHeight;
  36.                         hValue := left - destRect.left;
  37.                         if vMax < 0 then
  38.                             vMax := 0;
  39.                         if vValue < 0 then
  40.                             vValue := 0;
  41.                         if hMax < 0 then
  42.                             hMax := 0;
  43.                         if vValue < 0 then
  44.                             vValue := 0;
  45.                         SetCtlMax(vTextScrollBar, vMax);
  46.                         SetCtlValue(vTextScrollBar, vValue);
  47.                         SetCtlMax(hTextScrollBar, hMax);
  48.                         SetCtlValue(hTextScrollBar, hValue);
  49.                     end;
  50.                 hunlock(handle(TextTE));
  51.             end;
  52. {ShowMessage(concat('nListColumns= ', Long2str(nListColumns), cr, 'hListPageSize= ', long2str(hListPageSize)));}
  53.     end;
  54.  
  55.  
  56.     procedure SetTextInfo;
  57.   {Updates TextInfo so it points to the active text window.}
  58.         var
  59.             kind: integer;
  60.     begin
  61.         kind := CurrentWindow;
  62.     end;
  63.  
  64.  
  65.     procedure UpdateTextWindow (WhichWindow: WindowPtr);
  66.     begin
  67.         TextInfo := TextInfoPtr(WindowPeek(WhichWindow)^.RefCon);
  68.         if TextInfo <> nil then
  69.             with TextInfo^ do begin
  70.                     SetPort(TextWindowPtr);
  71.                     DrawControls(TextWindowPtr);
  72.                     DrawGrowIcon(TextWindowPtr);
  73.                     EraseRect(TextTE^^.viewRect);
  74.                     TEUpdate(TextTE^^.viewRect, TextTE);
  75.                     UpdateScrollBars;
  76.                 end; {with}
  77.         SetTextInfo;
  78.     end;
  79.  
  80.  
  81.     procedure ActivateTextWindow (WhichWindow: WindowPtr; Activating: boolean);
  82.     begin
  83.         if Activating then
  84.             UpdateTextWindow(WhichWindow);
  85.         TextInfo := TextInfoPtr(WindowPeek(WhichWindow)^.RefCon);
  86.         if TextInfo <> nil then
  87.             with TextInfo^ do
  88.                 if Activating then begin
  89.                         TEActivate(TextTE);
  90.                         ShowControl(hTextScrollBar);
  91.                         ShowControl(vTextScrollBar);
  92.                         WhatToUndo := NothingToUndo;
  93.                     end
  94.                 else begin
  95.                         TEDeactivate(TextTE);
  96.                         HideControl(hTextScrollBar);
  97.                         HideControl(vTextScrollBar);
  98.                     end;
  99.         SetTextInfo;
  100.     end;
  101.  
  102.  
  103.     procedure SetFontSize;
  104.         var
  105.             fInfo: FontInfo;
  106.     begin
  107.         with TextInfo^ do begin
  108.                 SetPort(TextWindowPtr);
  109.                 TextFont(CurrentFontID);
  110.                 TextSize(CurrentSize);
  111.                 with TextTE^^, fInfo do begin
  112.                         GetFontInfo(fInfo);
  113.                         TxSize := CurrentSize;
  114.                         LineHeight := ascent + descent + leading;
  115.                         FontAscent := ascent;
  116.                     end;
  117.             end;
  118.     end;
  119.  
  120.  
  121.     procedure InitTextEdit;
  122.         var
  123.             dRect, vRect: rect;
  124.     begin
  125.         with TextInfo^ do begin
  126.                 SetPort(TextWindowPtr);
  127.                 SetRect(vrect, 0, 0, TextWidth - ScrollBarWidth, TextHeight - ScrollBarWidth);
  128.                 drect := vrect;
  129.                 InsetRect(drect, 4, 4);
  130.                 TextTE := TENew(drect, vrect);
  131.                 with TextTE^^ do begin
  132.                         TxFont := CurrentFontID;
  133.                         SetFontSize;
  134.                         crOnly := 1; {do word wrap}
  135.                     end;
  136.                 TESetSelect(0, 0, TextTE);
  137.                 UpdateScrollBars;
  138.                 TEAutoView(true, TextTE); {Enable auto-scrolling}
  139.             end;
  140.     end;
  141.  
  142.  
  143.     procedure ScrollText;
  144.         var
  145.             value: integer;
  146.     begin
  147.         with TextInfo^, TextInfo^.TextTE^^ do
  148.             TEScroll(0, (viewRect.top - destRect.top) - (GetCtlValue(vTextScrollBar) * LineHeight), TextTE);
  149.     end;
  150.  
  151.  
  152.     procedure ScrAction (theCtl: ControlHandle; partCode: integer);
  153.         var
  154.             bInc, pInc, delta: integer;
  155.     begin
  156.         if TextInfo <> nil then
  157.             with TextInfo^ do begin
  158.                     if theCtl = vTextScrollBar then begin
  159.                             bInc := 1;
  160.                             pInc := vTextPageSize
  161.                         end
  162.                     else begin
  163.                             bInc := 4;
  164.                             pInc := hTextPageSize
  165.                         end;
  166.                     case partCode of
  167.                         inUpButton: 
  168.                             delta := -bInc;
  169.                         inDownButton: 
  170.                             delta := bInc;
  171.                         inPageUp: 
  172.                             delta := -pInc;
  173.                         inPageDown: 
  174.                             delta := pInc;
  175.                         otherwise
  176.                             exit(ScrAction);
  177.                     end;
  178.                     SetCtlValue(theCtl, GetCtlValue(theCtl) + delta);
  179.                     ScrollText;
  180.                 end; {with}
  181.     end;
  182.  
  183.  
  184.     procedure DoMouseDownInText (event: EventRecord; WhichWindow: WindowPtr);
  185.         var
  186.             theCtl: ControlHandle;
  187.             cValue: integer;
  188.             loc: point;
  189.     begin
  190.         TextInfo := TextInfoPtr(WindowPeek(WhichWindow)^.RefCon);
  191.         if TextInfo = nil then
  192.             exit(DoMouseDownInText);
  193.         SelectWindow(WhichWindow);
  194.         SetPort(WhichWindow);
  195.         loc := event.where;
  196.         GlobalToLocal(loc);
  197.         with TextInfo^ do
  198.             if PtInRect(loc, TextTE^^.viewRect) then begin
  199.                     TEClick(loc, BitTst(@event.modifiers, 6), TextTE);
  200.                     UpdateScrollBars;
  201.                 end
  202.             else
  203.                 case FindControl(loc, WhichWindow, theCtl) of
  204.                     inUpButton, inDownButton, inPageUp, inPageDown: 
  205.                         if TrackControl(theCtl, loc, @ScrAction) <> 0 then
  206.                             ;
  207.                     inThumb: 
  208.                         if TrackControl(theCtl, loc, nil) <> 0 then
  209.                             ScrollText;
  210.                     otherwise
  211.                 end;
  212.     end;
  213.  
  214.  
  215.     procedure GrowTextWindow (NewSize: LongInt);
  216.     begin
  217.         if TextInfo <> nil then
  218.             with TextInfo^ do begin
  219.                     TextWidth := LoWord(NewSize);
  220.                     TextHeight := hiWord(NewSize);
  221.                     SetPort(TextWindowPtr);
  222.                     SizeWindow(TextWindowPtr, TextWidth, TextHeight, true);
  223.                     EraseRect(TextWindowPtr^.PortRect);
  224.                     MoveControl(hTextScrollBar, -1, TextHeight - ScrollBarWidth);
  225.                     MoveControl(vTextScrollBar, TextWidth - ScrollBarWidth, -1);
  226.                     SizeControl(hTextScrollBar, TextWidth - 13, ScrollBarWidth + 1);
  227.                     SizeControl(vTextScrollBar, ScrollBarWidth + 1, TextHeight - 13);
  228.                     InvalRect(TextWindowPtr^.PortRect);
  229.                     with TextTE^^ do begin
  230.                             SetRect(viewRect, 0, 0, TextWidth - ScrollBarWidth, TextHeight - ScrollBarWidth);
  231.                             viewRect.bottom := (viewRect.bottom div lineHeight) * lineHeight;
  232.                             destRect := viewRect;
  233.                             InsetRect(destRect, 4, 4);
  234.                         end;
  235.                     TECalText(TextTE);
  236.                     ScrollText;
  237.                 end; {with}
  238.     end;
  239.  
  240.  
  241.     function MakeNewTextWindow (name: str255; width, height: integer): boolean;
  242.         var
  243.             wrect, crect: rect;
  244.     begin
  245.         MakeNewTextWindow := false;
  246.         if nTextWindows >= 10 then begin
  247.                 PutMessage(concat('NIH Image cannot open more than ', long2str(MaxTextWindows), ' text windows.'));
  248.                 exit(MakeNewTextWindow);
  249.             end;
  250.         TextInfo := TextInfoPtr(NewPtr(SizeOf(TextInfoRec)));
  251.         if TextInfo = nil then
  252.             exit(MakeNewTextWindow);
  253.         with TextInfo^ do begin
  254.                 TextWidth := width;
  255.                 TextHeight := height;
  256.                 TextLeft := PicLeft;
  257.                 TextTop := PicTop;
  258.                 PicLeft := PicLeft + hPicOffset;
  259.                 PicTop := PicTop + vPicOffset;
  260.                 if ((PicLeft + TextWidth) > ScreenWidth) or ((PicTop + TextHeight) > ScreenHeight) then begin
  261.                         PicLeft := PicLeftBase;
  262.                         PicTop := PicTopBase;
  263.                     end;
  264.                 if (TextTop + TextHeight) > ScreenHeight then
  265.                     TextHeight := ScreenHeight - TextTop - 4;
  266.                 SetRect(wrect, TextLeft, TextTop, TextLeft + TextWidth, TextTop + TextHeight);
  267.                 TextWindowPtr := NewWindow(nil, wrect, name, true, 0, pointer(-1), true, 0);
  268.                 if TextWindowPtr = nil then begin
  269.                         DisposPtr(ptr(TextInfo));
  270.                         TextInfo := nil;
  271.                         exit(MakeNewTextWindow);
  272.                     end;
  273.                 WindowPeek(TextWindowPtr)^.WindowKind := TextKind;
  274.                 WindowPeek(TextWindowPtr)^.RefCon := LongInt(TextInfo);
  275.                 SetRect(crect, TextWidth - ScrollBarWidth, -1, TextWidth + 1, TextHeight - 14);
  276.                 vTextScrollBar := NewControl(TextWindowPtr, crect, '', true, 0, 0, TextHeight - 14, ScrollBarProc, 0);
  277.                 SetRect(crect, -1, TextHeight - ScrollBarWidth, TextWidth - 14, TextHeight + 1);
  278.                 hTextScrollBar := NewControl(TextWindowPtr, crect, '', true, 0, 0, TextWidth - 14, ScrollBarProc, 0);
  279.                 InitTextEdit;
  280.                 DrawControls(TextWindowPtr);
  281.                 WhatToUndo := NothingToUndo;
  282.                 TextTitle := name;
  283.                 TextRefNum := 0;
  284.                 Changes := false;
  285.                 TooBig := false;
  286.                 InsMenuItem(WindowsMenuH, 'Dummy', WindowsMenuItems - 1 + nTextWindows);
  287.                 SetItem(WindowsMenuH, WindowsMenuItems + nTextWindows, name);
  288.                 nTextWindows := nTextWindows + 1;
  289.                 WindowNum := nTextWindows;
  290.                 TextWindow[nTextWindows] := TextWindowPtr;
  291.                 MakeNewTextWindow := true;
  292.             end; {with}
  293.     end;
  294.  
  295.  
  296.     function OpenTextFile (name: str255; RefNum: integer): boolean;
  297.         var
  298.             err: OSErr;
  299.             f, item: integer;
  300.             TextFileSize: LongInt;
  301.             LargerThan32K: boolean;
  302.     begin
  303.         OpenTextFile := false;
  304.         if FreeMem < MinFree then begin
  305.                 PutMessage('Not enough memory to open this text file.');
  306.                 exit(OpenTextFile);
  307.             end;
  308.         LargerThan32K := false;
  309.         err := FSOpen(name, RefNum, f);
  310.         err := GetEof(f, TextFileSize);
  311.         if TextFileSize > MaxTextBufSize then begin
  312.                 item := PutMessageWithCancel('This text file is larger than 32K. Would you like to to open the first 32K?');
  313.                 if item = cancel then begin
  314.                         err := fsclose(f);
  315.                         exit(OpenTextFile);
  316.                     end
  317.                 else begin
  318.                         TextFileSize := 30000;
  319.                         LargerThan32K := true;
  320.                     end;
  321.             end;
  322.         if not MakeNewTextWindow(name, 500, 400) then begin
  323.                 err := fsclose(f);
  324.                 exit(OpenTextFile);
  325.             end;
  326.         with TextInfo^ do begin
  327.                 SetHandleSize(TextTE^^.hText, TextFileSize);
  328.                 if MemError <> noErr then begin
  329.                         err := fsclose(f);
  330.                         PutMessage('Out of memory.');
  331.                         DisposePtr(ptr(TextInfo));
  332.                         TextInfo := nil;
  333.                         exit(OpenTextFile);
  334.                     end;
  335.                 err := SetFPos(f, fsFromStart, 0);
  336.                 ShowWatch;
  337.                 TextTE^^.teLength := TextFileSize;
  338.                 err := fsRead(f, TextFileSize, TextTE^^.hText^);
  339.                 if err <> noErr then begin
  340.                         TextTE^^.teLength := 0;
  341.                         SetHandleSize(TextTE^^.hText, 0);
  342.                         err := fsclose(f);
  343.                         exit(OpenTextFile);
  344.                     end;
  345.                 TECalText(TextTE);
  346.                 TextTitle := name;
  347.                 TextRefNum := RefNum;
  348.                 TooBig := LargerThan32K;
  349.             end; {with}
  350.         err := fsclose(f);
  351.         OpenTextFile := true;
  352.     end;
  353.  
  354.  
  355.     procedure DoKeyDownInText (ch: char);
  356.     begin
  357.         if TextInfo <> nil then begin
  358.                 TEKey(ch, TextInfo^.TextTE);
  359.                 TextInfo^.Changes := true;
  360.                 UpdateScrollBars;
  361. {with TextInfo^ do ShowMessage(concat(long2str(TextTE^^.teLength), '  ', long2str(GetHandleSize(TextTE^^.hText))));}
  362.                 WhatToUndo := NothingToUndo;
  363.             end;
  364.     end;
  365.  
  366.  
  367.     procedure ChangeFontOrSize;
  368.     begin
  369.         if TextInfo <> nil then
  370.             with TextInfo^ do begin
  371.                     TextTE^^.TxFont := CurrentFontID;
  372.                     SetFontSize;
  373.                     SetPort(TextWindowPtr);
  374.                     EraseRect(TextTE^^.viewRect);
  375.                     TEUpdate(TextTE^^.viewRect, TextTE);
  376.                     UpdateScrollBars;
  377.                 end; {with}
  378.     end;
  379.  
  380.  
  381.     procedure DoTextCopy;
  382.         var
  383.             err: OSErr;
  384.     begin
  385.         if TextInfo <> nil then begin
  386.                 TECopy(TextInfo^.TextTE);
  387.                 err := ZeroScrap;
  388.                 if err = NoErr then begin
  389.                         err := TEToScrap;
  390.                         WhatsOnClip := NothingOnClip; {It is on System Scrap}
  391.                     end;
  392.             end;
  393.     end;
  394.  
  395.  
  396.     procedure DoTextPaste;
  397.         var
  398.             err: OSErr;
  399.     begin
  400.         if TextInfo <> nil then begin
  401.                 err := TEFromScrap;
  402.                 if err = NoErr then
  403.                     TEPaste(TextInfo^.TextTE);
  404.                 TextInfo^.Changes := true;
  405.                 UpdateScrollBars;
  406.                 WhatToUndo := NothingToUndo;
  407.             end;
  408.     end;
  409.  
  410.  
  411.     procedure DoTextClear;
  412.         var
  413.             err: OSErr;
  414.     begin
  415.         if TextInfo <> nil then begin
  416.                 TEDelete(TextInfo^.TextTE);
  417.                 TextInfo^.Changes := true;
  418.             end;
  419.         UpdateScrollBars;
  420.         WhatToUndo := NothingToUndo;
  421.     end;
  422.  
  423.  
  424.     procedure DoSaveText;
  425.         var
  426.             err, f: integer;
  427.             TheInfo: FInfo;
  428.             ByteCount: LongInt;
  429.     begin
  430.         if TextInfo <> nil then
  431.             with TextInfo^ do begin
  432.                     hlock(handle(TextTE));
  433.                     with TextTE^^ do begin
  434.                             ByteCount := TELength;
  435.                             if ByteCount = 0 then
  436.                                 exit(DoSaveText);
  437.                             err := GetFInfo(TextTitle, TextRefNum, TheInfo);
  438.                             case err of
  439.                                 NoErr: 
  440.                                     if TheInfo.fdType <> 'TEXT' then begin
  441.                                             TypeMismatch(TextTitle);
  442.                                             exit(DoSaveText)
  443.                                         end;
  444.                                 FNFerr:  begin
  445.                                         err := create(TextTitle, TextRefNum, 'Imag', 'TEXT');
  446.                                         if CheckIO(err) <> 0 then
  447.                                             exit(DoSaveText);
  448.                                     end;
  449.                                 otherwise
  450.                                     if CheckIO(err) <> 0 then
  451.                                         exit(DoSaveText)
  452.                             end;
  453.                             ShowWatch;
  454.                             err := fsopen(TextTitle, TextRefNum, f);
  455.                             if CheckIO(err) <> 0 then
  456.                                 exit(DoSaveText);
  457.                             err := fswrite(f, ByteCount, hText^);
  458.                             if CheckIO(err) <> 0 then
  459.                                 exit(DoSaveText);
  460.                             err := SetEof(f, ByteCount);
  461.                             err := fsclose(f);
  462.                             err := FlushVol(nil, TextRefNum);
  463.                             Changes := false;
  464.                         end; {with}
  465.                     hunlock(handle(TextTE));
  466.                 end; {with}
  467.     end;
  468.  
  469.  
  470.     procedure SaveTextAs;
  471.         var
  472.             where: Point;
  473.             reply: SFReply;
  474.     begin
  475.         if TextInfo <> nil then begin
  476.                 where.v := 60;
  477.                 where.h := 100;
  478.                 SFPutFile(where, 'Save Text as?', TextInfo^.TextTitle, nil, reply);
  479.                 if reply.good then
  480.                     with reply, TextInfo^ do begin
  481.                             TextTitle := fname;
  482.                             TextRefNum := vRefNum;
  483.                             DoSaveText;
  484.                             SetWTitle(TextWindowPtr, TextTitle);
  485.                             SetItem(WindowsMenuH, WindowsMenuItems - 1 + WindowNum, TextTitle);
  486.                         end;
  487.             end;
  488.     end;
  489.  
  490.  
  491.     procedure SaveText;
  492.     begin
  493.         if TextInfo <> nil then begin
  494.                 with TextInfo^ do
  495.                     if (TextRefNum = 0) or TooBig then
  496.                         SaveTextAs
  497.                     else
  498.                         DoSaveText;
  499.             end;
  500.     end;
  501.  
  502.  
  503.     function SaveTextChanges: integer;
  504.         const
  505.             yesID = 1;
  506.             NoID = 2;
  507.             CancelID = 3;
  508.         var
  509.             id: integer;
  510.             reply: SFReply;
  511.     begin
  512.         id := 0;
  513.         with TextInfo^ do
  514.             if changes and not TooBig then begin
  515.                     if macro and (MacroCommand = DisposeC) then begin
  516.                             SaveTextChanges := ok;
  517.                             exit(SaveTextChanges);
  518.                         end;
  519.                     ParamText(TextTitle, '', '', '');
  520.                     InitCursor;
  521.                     id := alert(600, nil);
  522.                     if id = yesID then
  523.                         SaveText;
  524.                 end; {if changes}
  525.         if id = cancelID then
  526.             SaveTextChanges := cancel
  527.         else
  528.             SaveTextChanges := ok;
  529.     end;
  530.  
  531.  
  532.     procedure InsertText (str: str255; EndOfLine: boolean);
  533.         var
  534.             i: integer;
  535.     begin
  536.         if TextInfo <> nil then
  537.             with TextInfo^ do begin
  538.                     if EndOfLine then
  539.                         str := concat(str, cr);
  540.                     for i := 1 to length(str) do
  541.                         TEKey(str[i], TextTE);
  542.                     Changes := true;
  543.                     UpdateScrollBars;
  544.                     WhatToUndo := NothingToUndo;
  545.                 end;
  546.     end;
  547.  
  548.  
  549.     procedure GoToLine (str: str255; data: CharArrayPtr);
  550.         var
  551.             pos, line: integer;
  552.             found: boolean;
  553.             n: LongInt;
  554.     begin
  555.         with TextInfo^.TextTE^^ do begin
  556.                 found := false;
  557.                 delete(str, 1, 1);
  558.                 StringToNum(str, n);
  559.                 pos := 0;
  560.                 line := 1;
  561.                 if n = 1 then
  562.                     found := true
  563.                 else
  564.                     repeat
  565.                         if data^[pos] = cr then
  566.                             line := line + 1;
  567.                         pos := pos + 1;
  568.                         if line = n then begin
  569.                                 found := true;
  570.                                 leave;
  571.                             end;
  572.                     until (pos >= teLength);
  573.                 if found then begin
  574.                         TESetSelect(pos, pos, TextInfo^.TextTE);
  575.                         TEKey('x', TextInfo^.TextTE);
  576.                         TEKey(BackSpace, TextInfo^.TextTE);
  577.                         UpdateScrollBars;
  578.                     end
  579.                 else
  580.                     beep;
  581.             end;
  582.     end;
  583.  
  584.  
  585.     procedure DoFind;
  586.         const
  587.             StringID = 3;
  588.         var
  589.             mylog: DialogPtr;
  590.             item: integer;
  591.             i, firstpos, lastpos, pos: integer;
  592.             slength: integer;
  593.             match: boolean;
  594.             data: CharArrayPtr;
  595.             c: char;
  596.             str: str255;
  597.     begin
  598.         if TextInfo = nil then
  599.             exit(DoFind);
  600.         hlock(handle(TextInfo^.TextTE));
  601.         with TextInfo^.TextTE^^ do begin
  602.                 if not OptionKeyWasDown then begin
  603.                         InitCursor;
  604.                         ParamText('What would you like to find?', '', '', '');
  605.                         mylog := GetNewDialog(170, nil, pointer(-1));
  606.                         SetDString(MyLog, StringID, SearchString);
  607.                         SelIText(MyLog, StringID, 0, 32767);
  608.                         OutlineButton(MyLog, ok, 16);
  609.                         repeat
  610.                             ModalDialog(nil, item);
  611.                         until (item = ok) or (item = cancel);
  612.                         if item = cancel then begin
  613.                                 DisposDialog(mylog);
  614.                                 exit(DoFind)
  615.                             end;
  616.                         SearchString := GetDString(MyLog, StringID);
  617.                         DisposDialog(mylog);
  618.                     end;
  619.                 slength := Length(SearchString);
  620.                 if slength = 0 then
  621.                     exit(DoFind);
  622.                 str := SearchString;
  623.                 MakeLowerCase(str);
  624.                 data := CharArrayPtr(htext^);
  625.                 if (slength > 1) and (str[1] = '#') and (str[2] >= '0') and (str[2] <= '9') then begin
  626.                         GoToLine(str, data);
  627.                         hunlock(handle(TextInfo^.TextTE));
  628.                         exit(DoFind);
  629.                     end;
  630.                 match := false;
  631.                 lastpos := teLength - slength - 1;
  632.                 match := false;
  633.                 for firstpos := selEnd to lastpos do begin
  634.                         match := true;
  635.                         for i := 1 to slength do begin
  636.                                 c := data^[firstpos + i - 1];
  637.                                 if (c >= 'A') and (c <= 'Z') then
  638.                                     c := chr(ord(c) + 32);
  639.                                 if c <> str[i] then begin
  640.                                         match := false;
  641.                                         leave
  642.                                     end;
  643.                             end;
  644.                         if match then begin
  645.                                 pos := firstpos;
  646.                                 leave;
  647.                             end;
  648.                     end;
  649.                 if match then begin
  650.                         TESetSelect(pos, pos, TextInfo^.TextTE);
  651.                         TEKey('x', TextInfo^.TextTE);
  652.                         TEKey(BackSpace, TextInfo^.TextTE);
  653.                         TESetSelect(pos, pos + slength, TextInfo^.TextTE);
  654.                         UpdateScrollBars;
  655.                     end
  656.                 else
  657.                     beep;
  658.             end; {with}
  659.         hunlock(handle(TextInfo^.TextTE));
  660.     end;
  661.  
  662.  
  663.  
  664. end.